frame
The frame property defines the size and alignment of a view. You can specify it in one of two formats:
1. Fixed Width and Height
This format allows you to specify a fixed width and/or height for the view, as well as how it is aligned within that frame.
Example
2. Flexible Frame Constraints
This format gives more control over layout by specifying minimum, maximum, and ideal dimensions for the frame. These values can be numeric or 'infinity', which instructs the view to expand to fill available space.
Example
Alignment
The alignment property determines how the view is positioned within the frame. Common alignment values include:
'center''top''bottom''leading''trailing''topLeading''topTrailing''bottomLeading''bottomTrailing'
Note: Alignment only affects layout when the frame size exceeds the view’s natural size.
Example
Best Practices
- Use the fixed
widthandheightformat when you want precise dimensions. - Use the flexible format with
min/max/idealvalues when working with responsive layouts. - Avoid specifying both
width/heightandminWidth/maxWidth, etc., in the same frame object — choose one format to avoid conflicts.
Summary
The frame property in CommonViewProps allows fine-grained control over layout sizing and alignment, closely mirroring SwiftUI’s native frame modifier. Use it to design clean and adaptable interfaces across different screen sizes.
